﻿using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Xml.Linq;

namespace EntryExit
{
    public class ConfigMgr
    {
        private Dictionary<string,string> mConfigMapping { get; set; }
        public static ConfigMgr mInstance { get; set; }

        private ConfigMgr()
        {
            mConfigMapping = new Dictionary<string, string>();
            LoadConfigValues();
        }

        public static ConfigMgr Instance
        {
            get
            {
                if (mInstance == null)
                {
                    mInstance = new ConfigMgr();
                }
                return mInstance;
            }
        }

        public void LoadConfigValues()
        {
            string assemblyLocation = Assembly.GetExecutingAssembly().CodeBase;
            string theDirectory = Path.GetDirectoryName(assemblyLocation);
            string configFilePath = Path.Combine(theDirectory, "EYConfig.xml");

            XDocument doc = XDocument.Load(configFilePath);
            mConfigMapping = doc.Descendants("Config").ToDictionary(x => x.Attribute("Name").Value, x => x.Attribute("Value").Value);

        }

        public string GetValue(string keyName)
        {
            if (mConfigMapping.ContainsKey(keyName))
            {
                return mConfigMapping[keyName];
            }
            else
            {
                return string.Empty;
            }
        }

    }

    public class ConfigKeys
    {
        public static string CNFG_CARDAX_CENTRAL_CONNECTION = "CardaxCentralConnection";
        public static string CNFG_CARDAX_EVENT_CONNECTION = "CardaxEventConnection";
        public static string CNFG_HRMS_CONNECTION = "HRMSConnection";
        public static string CNFG_MIN_WORK_HOURS = "MinWorkHours";
        public static string CNFG_MAX_WORK_HOURS = "MaxWorkHours";
        public static string CNFG_MIN_YEAR = "MinYear";
        public static string CNFG_MAX_YEAR = "MaxYear";
        public static string CNFG_TEST_USER = "TestUser";
        public static string CNFG_ADMIN_USERS = "AdminUsersLPN";
        public static string CNFG_DATA_PULL_EXE_PATH = "DataPullExePath";
        public static string CNFG_QUEEN_ROLE_USER = "QueenRoleUser";
        public static string CNFG_LOWEST_WORK_HOURS = "LowestBoundaryWorkHours";
        public static string CNFG_SHIFT_SDTOOL = "SDToolLink";
        public static string CNFG_LEAVE_LMS = "LMSLink";
        public static string CNFG_DATE_FORMAT = "DateFormat";
        public static string CNFG_TIMEOUTVALUE = "Timeoutvalue";
    }
    
}